<?php
namespace Admin\Controller;
use Think\Controller;
class ClubController extends Controller {
    //显示列表
    public function clublist(){
        $clubmodel=M('club');
        $club=$clubmodel->select();
        $this->club=$club;
        $this->display();
}
//添加列表
   function addclub(){
        $pic=$_POST['pic'];
        $jname=$_POST['jname'];
        $intro=$_POST['intro'];
        $teacher=$_POST['teacher'];
        $tel=$_POST['tel'];
        $number=$_POST['number'];
        $club=D('club');     
        if ($club->create()) 
        {
            if (false !== $club->add()) {
                //echo $user->getLastSql();
                $this->success('添加成功！', 'clublist');
            }
            else
            {
                $this->error('添加失败，数据错误','clublist');
            }
        }
            $this->display();
        }

//        function delclub(){
//         $jid=$_POST['jid'];
//         $club=M("club");
//         $clubdata=$club->where('jid='.$jid)->find();
//         unlink('./Public/upload/'.$clubdata['pic']);
//         if(false!=$club->where('jid='.$jid)->delete()){
//             $result['msg']=1;
//             $this->ajaxReturn($result);
//         }else{
//             $result['msg']=0;
//             $this->ajaxReturn($result);
//         }
// }

    // }
        //删除俱乐部
        function delclub(){
       $jid = $_GET['id'];
        $data=M('club')->where(array('jid'=>$jid))->find();
        if($data){
                $re=M('club')->where(array('jid'=>$jid))->delete();
            if($re)
                $this->success('删除成功！',U('clublist'));
            else
                $this->error('删除失败！',U('clublist'));
        }
        }

      //显示修改俱乐部
    function clubmod(){
            $jid = $_GET['id'];
            $re = M('club')->where('jid='.$jid)->find();
            $this->re = $re;
            $this->display();
        }
//修改俱乐部
        function clubmod1(){
            //$class = M("class");
            $jid = $_POST['jid'];
            $data['pic']=$_POST['pic'];
            $data['jname']=$_POST['jname'];
            $data['intro'] = $_POST['intro'];
            $data['teacher'] = $_POST['teacher'];
            $data['tel'] = $_POST['tel'];
            $data['number'] = $_POST['number'];
            
            $int = M('club')->where('jid='.$jid)->save($data);
            if($int){
                $this->success('修改成功！','clublist');
            }
            else{
                echo "$data";
                $this->error('修改失败！','clublist');
            }
    
        }
   
   //搜索俱乐部列表
     //    public function searchclub(){
     //    $key = $_GET['key'];
     //    $clubnum = M('club')->where('jname like "%'.$key.'%"')->count();
     //    $Page = new \Think\Page($clubnum,2);
     //    $this->clubnum =$clubnum;
     //    $this->clubpage=$Page->show();
     //    if (clubnum) {
     //    $this->clublist=M('club')
     //        ->where('jname like "%'.$key.'%"')
     //        ->order('jid')
     //        ->limit($Page->firstRow,2)
     //        ->select();
     //    }
     // else $this->error('没有相关信息！');
     //    }  

         public function searchclub(){
        $key=$_POST['jname'];
        echo "$key";
        $search=M('club');
        $search=$search->where("jname like '%$key%'" )->select();
        $this->search=$search;
    
        $this->display();
   }

}